package com.klhappy.houyuan.adapter;


import java.util.List;
import butterknife.ButterKnife;
import butterknife.InjectView;
import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.FamilyBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.view.ImageManager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FamilyMemberAdapter extends BaseAdapter{

	private List<FamilyBean.Records> records;
	private Context mContext;
	
	public FamilyMemberAdapter(Context context, List<FamilyBean.Records> records) {
		this.records = records;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return records.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		records.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.family_member_item, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder)convertView.getTag();
		}


		ImageManager.loadImage(UrlConstant.BASE_URL + records.get(position).getOwn_icon() ,holder.ivFm);
		holder.tvFm.setText(records.get(position).getRelation());
		holder.tvFn.setText(records.get(position).getOwn_mob_no());
		holder.tvFa.setText(records.get(position).getRec_addr());
		
		return convertView;
	}
	
	static class ViewHolder {
		@InjectView(R.id.iv_family_member) ImageView ivFm;
		@InjectView(R.id.tv_family_member) TextView tvFm;
		@InjectView(R.id.tv_family_number) TextView tvFn;
		@InjectView(R.id.tv_family_address) TextView tvFa;

		
		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}
	}
}
